﻿// -----------------------------------------------------------------------
// <copyright file="Vehicle.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Ex03.GarageLogic
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Reflection;
    
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class Vehicle
    {
        private string m_LicensePlate;
        private string m_ModulName;
        private float m_PercentEnergyLeft;
        private List<Tire> m_TireCollection;
        private EnergySource m_EnergySource;

        internal List<Tire> TireCollection
        {
            get { return m_TireCollection; }
            set { m_TireCollection = value; }
        }

        public EnergySource SourceOfEnergy
        {
            get { return m_EnergySource; }
            set { m_EnergySource = value; }
        }

        public string ModulName
        {
            get { return m_ModulName; }
            set { m_ModulName = value; }
        }

        public string LicensePlate
        {
            get { return m_LicensePlate; }
            set { m_LicensePlate = value; }
        }

        public float PercentEnergyLeft
        {
            get { return m_PercentEnergyLeft; }
            set { m_PercentEnergyLeft = value; }
        }

        protected internal void CalculatePercentEnergyLeft()
        {
            m_PercentEnergyLeft = (m_EnergySource.CurrentEnergyLevel * 100) / m_EnergySource.MaxEnergyLevel;
        }

        internal void AddMaxAirPressureToAllTires()
        {
            foreach (Tire tireToFill in m_TireCollection)
            {
                tireToFill.AddMaxAirPressure();
            }
        }

        /// <summary>
        /// Collects information about the vehicle with all its inner parameters into a string format
        /// </summary>
        /// <param name="o_VehicleData">string in which the vehicle is gathered</param>
        internal virtual void GetVehicleData(ref StringBuilder o_VehicleData)
        {
            o_VehicleData.AppendFormat(
                "{0}Modul Name: {1}{0}Plate Number: {2}{0}Energy Level: {3}%{4}",
                Environment.NewLine,
                m_ModulName,
                m_LicensePlate,
                string.Format("{0:0.00}", m_PercentEnergyLeft),
                Environment.NewLine);
            m_EnergySource.GetEngineData(ref o_VehicleData);

            int i = 1;
            foreach (Tire tire in m_TireCollection)
            {
                o_VehicleData.AppendFormat("{0}Tire {1} data:", Environment.NewLine, i);
                tire.GetTireData(ref o_VehicleData);
                i++;
            }
        }

        public static List<Type> from { get; set; }
    }
}
